<!DOCTYPE html>
<html>

<head>

	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">


	<title>试卷管理</title>

	<link rel="shortcut icon" href="favicon.ico">
	<link href="${ctx}/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
	<link href="${ctx}/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">

	<!-- Data Tables -->
	<link href="${ctx}/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
	<link rel="stylesheet" href="${ctx}/css/labelauty.css"/>
	<link href="${ctx}/css/plugins/iCheck/custom.css" rel="stylesheet">
	<link href="${ctx}/css/animate.min.css" rel="stylesheet">
	<link href="${ctx}/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <style>
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
	<div class="row">
		<div class="col-sm-12">
			<div class="ibox float-e-margins">
				<div class="ibox-content">
					<div class="text-center">
						<form class="form-inline">
							<div class="form-group">
								<label class="control-label">审核状态</label>
								<select class="form-control" id="checkStatus">
									<option value="">全部</option>
									<option value="0">未审核</option>
									<option value="1">一审通过</option>
									<option value="2">二审通过</option>
									<option value="3">三审通过</option>
									<option value="4">一审未过</option>
									<option value="5">二审未过</option>
									<option value="6">三审未过</option>
								</select>
							</div>
							<div class="form-group">
								<label class="control-label">试题分类</label>
								<select class="form-control" id="paperPattern">
									<option value="">全部</option>
									<option value="1">问答</option>
									<option value="2">常规化</option>
									<option value="3">客观化</option>
								</select>
							</div>
							<div class="form-group">
								<label class="control-label">试卷类型</label>
								<select class="form-control" id="paperType">
									<option value="">全部</option>
									<option value="1">A卷</option>
									<option value="2">B卷</option>
								</select>
							</div>
							<div class="form-group">
								<label class="control-label">年度</label>
								<select class="form-control" id="year" >
									<option value="">全部</option>
                                    <#list yearList as year>
									<option value="${year}">${year}</option>
                                    </#list>
								</select>
							</div>
							<div class="form-group">
								<div class="col-sm-3">
									<input type="text" class="form-control" placeholder="请输入试卷名称" id="paperName"/>
								</div>
							</div>
							<div class="form-group">
								<a class="btn btn-primary" id="search"><i class="glyphicon glyphicon-search"></i>&nbsp;筛选试题
								</a>
								<a class="btn btn-success" id="export" ><i class="glyphicon glyphicon-download-alt"></i>&nbsp;批量导出
								</a>
                                <input type="hidden" id="basePath" value="${ctx}">
							</div>

							<a href="javascript:location.reload();" class="pull-right btn btn-default"><i
									class="glyphicon glyphicon-refresh"></i></a>
						</form>

					</div>
					<table class="table table-striped table-bordered table-hover paper-table text-center">
						<thead>
						<tr>
							<th width="35" class="text-center">
								<label class="i-checks">
									<input type="checkbox" id="all_checked"/>
								</label>
							</th>
							<th class="text-center">试卷名称</th>
							<th class="text-center">站类型</th>
							<th class="text-center">试卷类别</th>
							<th class="text-center">年度</th>
							<th class="text-center">批次</th>
							<th class="text-center">操作人</th>
							<th class="text-center">操作时间</th>
							<th class="text-center">审核状态</th>
							<th class="text-center">操作</th>
						</tr>
						</thead>
					</table>

				</div>
			</div>
		</div>
	</div>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog" style="width: 480px;">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title" id="myModalLabel">
					请选择导出类型
				</h4>
			</div>
			<div class="modal-body">
				<div class="form-group">
					<div class="col-md-4 text-right">
						<input class="rdolist" type="radio" name="exportType" id="answer" value="1" checked>
						<label class="rdobox">
							<span class="check-image"></span>
							<span class="radiobox-content">仅试卷</span>
						</label>
					</div>
					<div class="col-md-4">
						<input class="rdolist" type="radio" name="exportType"  value="2">
						<label class="rdobox">
							<span class="check-image"></span>
							<span class="radiobox-content">试卷和答案</span>
						</label>
					</div>
					<div class="col-md-4">
						<input class="rdolist" type="radio" name="exportType"  value="3">
						<label class="rdobox">
							<span class="check-image"></span>
							<span class="radiobox-content">Excel试卷</span>
						</label>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭
				</button>
				<button type="button" onclick="batch_export()" class="btn btn-primary">
					确定
				</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
<script src="${ctx}/js/jquery.min.js?v=2.1.4"></script>
<script src="${ctx}/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${ctx}/js/plugins/layer/layer.js"></script>
<script src="${ctx}/js/plugins/dataTables/jquery.dataTables.min.js"></script>
<script src="${ctx}/js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script src="${ctx}/js/plugins/iCheck/icheck.min.js"></script>
<script src="${ctx}/js/labelauty.js"></script>
<script>
	var paperTable
	$(function () {
		$(".rdolist").labelauty("rdolist", "rdo");
		paperTable = $('.paper-table').dataTable({
			"aLengthMenu": [10, 20],
			"sDom": '<"top">rt<"bottom"flpi><"clear">',
			"bStateSave": true, //状态保存
			"bLengthChange": true,
			"bFilter": false,
			"bSort": false,
			"serverSide": true,
			"iDisplayLength": 10,
			"aoColumnDefs": [{"bSortable": false, "aTargets": [0, 7]}],
			"bScrollCollapse": true, //高度自适应
			"aaSorting": [[1, 8, "asc"]],
			"ajax": {
				url: "${ctx}/paper/list",
				type: "GET",
				cache: false,
				data: function (d) {
				    d.year = $("#year").val();
					d.paperPattern = $("#paperPattern").val();
					d.type = $("#paperType").val();
					d.name = $("#paperName").val();
					d.checkStatus = $("#checkStatus").val();
				}
			},
			"columns": [{
				"render": function (data, type, row, meta) {
					return "<label class='i-checks'><input type='checkbox' value="+row.id+" name='paperId'/></label>";
				}
			}, {
				"data": "name",
                "render":function(data, type, row, meta){
                    var text = '<a title=\"试卷详情\" onclick=paper_detail("' + row.id + '") style=\"text-decoration:none\">'+data+'</a>';
                    return text;
                }
			}, {
				"data": "type",
			}, {
				"data": "paperPattern",
			}, {
				"data": "year",
			}, {
				"data": "batch",
			}, {
				"data": "username",
			}, {
				"data": "updateTime"
			}, {
				"data": "checkStatus",
				"render": function (data, type, row, meta) {
					var text;
					if (data == "一审通过" || data == "二审通过" || data == "三审通过") {
						text = "<span class=\"label label-primary radius\">" + data + "</span>";
					} else {
						text = "<span class=\"label label-danger radius\">" + data + "</span>";
					}
					return text;
				}
			}, {
				"render": function (data, type, row, meta) {
				    var text = '<a onclick=paper_check(this,"' + row.id + '","' + row.checkStatus + '")  title=\"编辑\"  href=\"javascript:;\" style=\"text-decoration:none\">审核</a>&nbsp;&nbsp;' +
						    '<a title=\"撤销\" onclick=paper_revoke("' + row.id + '","' + row.checkStatus + '")  href=\"javascript:;\" style=\"text-decoration:none\"><i class="glyphicon glyphicon-arrow-left"></i></a>&nbsp;&nbsp;'+
						    '<a onclick=paper_update("' + row.id + '") title="\修改\" href="javascript:;" style="text-decoration:none"><i class="glyphicon glyphicon-pencil"></i> </a>';
				    if(row.checkStatus == "三审通过"){
					    text = '<a title=\"撤销\" onclick=paper_revoke("' + row.id + '","' + row.checkStatus + '")  href=\"javascript:;\" style=\"text-decoration:none\"><i class="glyphicon glyphicon-arrow-left"></i></a>&nbsp;&nbsp;';
					}else if(row.checkStatus == "未审核"){
					    text = '<a onclick=paper_check(this,"' + row.id + '","' + row.checkStatus + '")  title=\"编辑\"  href=\"javascript:;\" style=\"text-decoration:none\">审核</a>&nbsp;&nbsp;' +
							    '<a onclick=paper_delete("' + row.id + '") title="\删除\" href="javascript:;" style="text-decoration:none"><i class="glyphicon glyphicon-trash"></i> </a>&nbsp;&nbsp;'+
							    '<a onclick=paper_update("' + row.id + '") title="\修改\" href="javascript:;" style="text-decoration:none"><i class="glyphicon glyphicon-pencil"></i> </a>';
					}

					return text;
				}

			}]
		}).api();
		$('#search').click(function () {
			paperTable.ajax.reload();
		});
	})

	$(document).ajaxComplete(function () {
		$('input[type=checkbox]').iCheck({
			checkboxClass: "icheckbox_square-green",
			radioClass: "iradio_square-green"
		});

		$("#all_checked").on('ifChecked', function(event){
			$("input[name='paperId']").iCheck('check');
		});
		$("#all_checked").on('ifUnchecked', function(event){
			$("input[name='paperId']").iCheck('uncheck');
		});

	})


	//试卷审核
	function paper_check(obj, paperId, status) {
		//默认为通过
		var flag = true;
		layer.confirm('确定通过审核吗？', {
			btn: ['通过', '不通过']
		}, function () {
			$.ajax({
				url: "${ctx}/paper/check",
				type: "post",
				dataType: "json",
				data: {"paperId": paperId, "checkStatus": status, "flag": flag},
				success: function (data) {
					var result = data.status;
					if (result == "401") {
						layer.alert('您没有权限!', {
							icon: 4,
							skin: 'layer-ext-moon'
						})
					}else if (result == "200") {
						layer.alert('审核成功!', {
							icon: 1,
							skin: 'layer-ext-moon'
						},function(index){
                            paperTable.ajax.reload();
                            layer.close(index);
                        })

					} else {
						layer.alert('审核失败!', {
							icon: 2,
							skin: 'layer-ext-moon'
						})
					}
				}
			});
		}, function () {
			if (status == "一审未过" || status == "二审未过" || status == "三审未过") {
				return;
			}
			layer.prompt({title: '请输入未通过原因!', formType: 2}, function (text, index) {
				layer.close(index);
				flag = false;
				$.ajax({
					url: "${ctx}/paper/check",
					type: "post",
					dataType: "json",
					data: {"paperId": paperId, "checkStatus": status, "mark": text, "flag": flag},
					success: function (data) {
						var result = data.status;
						if (result == "401") {
							layer.alert('您没有权限!', {
								icon: 4,
								skin: 'layer-ext-moon'
							})
						}else if (result == "200") {
							layer.alert('审核未通过!', {
								icon: 1,
								skin: 'layer-ext-moon'
							},function(index){
                                paperTable.ajax.reload();
                                layer.close(index);
                            })
						}
					}
				});
			});
		});
	}

	//撤销审核
	function paper_revoke(paperId, status) {
		layer.confirm('确认要撤销审核吗？', function (index) {
			$.ajax({
				url: "${ctx}/paper/revoke",
				type: "POST",
				dataType: "json",
				data: {"paperId": paperId, "checkStatus": status},
				success: function (data) {
					var result = data.status;
					if (result == "401") {
						layer.alert('您没有权限!', {
							icon: 4,
							skin: 'layer-ext-moon'
						})
					}else if (result == "200") {
						layer.alert('撤销成功!', {
							icon: 1,
							skin: 'layer-ext-moon'
						},function (index) {
                            paperTable.ajax.reload();
                            layer.close(index);
						})
					} else {
						layer.alert('撤销失败!', {
							icon: 2,
							skin: 'layer-ext-moon'
						})
					}
				}
			});
		})
	}


	function paper_detail(paperId){
		layer.open({
			title: '试卷详情',
			type: 2,
			area: ['800px', '520px'],
			shadeClose: true, //点击遮罩关闭
			content: '${ctx}/paper/detail/'+paperId
		});
    }


    function paper_delete(paperId){
	    layer.confirm('确认要删除试卷吗？', function (index) {
		    $.ajax({
			    url: "${ctx}/paper/delete",
			    type: "POST",
			    dataType: "json",
			    data: {"paperId": paperId},
			    success: function (data) {
				    var result = data.status;
				    if (result == "401") {
					    layer.alert('您没有权限!', {
						    icon: 4,
						    skin: 'layer-ext-moon'
					    })
				    }else if (result == "200") {
					    layer.alert('删除成功!', {
						    icon: 1,
						    skin: 'layer-ext-moon'
					    },function (index) {
                            paperTable.ajax.reload();
                            layer.close(index);
					    })
				    } else {
					    layer.alert('删除失败!', {
						    icon: 2,
						    skin: 'layer-ext-moon'
					    })
				    }
			    }
		    });
	    })
    }

	function paper_update(paperId){
		var index = layer.open({
			type: 2,
			title: "试卷修改",
			content: "${ctx}/paper/update/"+paperId,
		});
		layer.full(index);
    }

    $(function(){
        $("#export").click(function(){
	        var checkData =[];
	        $("input[name='paperId']:checked").each(function(){
		        checkData.push($(this).val());
	        });

	        if(checkData.length == 0){
		        layer.alert('请选择试卷!', {
			        icon: 5,
			        skin: 'layer-ext-moon'
		        })
		        return;
	        }
	        $('#myModal').modal('show');
        })
    })
    function batch_export(){
	    var checkData =[];
	    $("input[name='paperId']:checked").each(function(){
		    checkData.push($(this).val());
	    });
	   var value =  $("input[name='exportType']:checked").val();
	    if(value=="1") {
            window.location.href = "${ctx}/export/word/paper?paperIds="+checkData;
        }else if (value == "2"){
            window.location.href = "${ctx}/export/word/paperAndAnswer?paperIds="+checkData;
        }else if(value == "3"){
		    window.location.href = "${ctx}/export/excel/acupoint?paperIds="+checkData;
        }
	    $('#myModal').modal('hide');
    }
</script>
</body>
</html>
